<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('码盘明细页面')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <input type="hidden" th:value="${id}" id="kid">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal add-btn">
                        <i class="layui-icon">&#x1005;</i> 多选打印
                    </a>

                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table1"></table>
                    </div>
                </section>
                <div class="layui-form-item">
                    <!--<div class="layui-input-block">-->
                        <!--<button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="editKq">立即提交</button>-->
                        <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                    <!--</div>-->
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="/public/public_js::public_js"></div>
<script>

    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent = {

            "click #btn_tz": function (e, value, row, index) {//调整
                btn_tz(row.id);
            }
        }

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;

        //打印
        function btn_tz(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("您将打印选择的订单", function (index) {
                zzpUtils.action({
                    url: "/wmspalletsorting/baseDyid" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        if(data.title=='码盘明细打印失败'){
                            setTimeout(function () {
                                layer.msg(data.message);
                            }, 500);
                        }else{
                            var LODOP=getLodop();
                            LODOP.PRINT_INIT('打印码盘信息');
                            for(var i=0;i<data.rows.length;i++){
                                var oDate = new Date(); //实例一个时间对象；
                                var time=oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate()+' '+oDate.getHours()+':'+oDate.getMinutes()+':'+oDate.getSeconds();
                                LODOP.ADD_PRINT_TEXT(28,34,270,30,time);
                                LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                                LODOP.ADD_PRINT_BARCODE(48,34,270,47,"EAN128B",data.rows[i].asnbh);
                                LODOP.ADD_PRINT_TEXT(110,34,100,30,"货品编号");
                                LODOP.ADD_PRINT_TEXT(110,100,307,30,data.rows[i].bh);
                                LODOP.ADD_PRINT_TEXT(140,34,100,30,"货品名称");
                                LODOP.ADD_PRINT_TEXT(140,100,307,30,data.rows[i].mc);
                                LODOP.ADD_PRINT_TEXT(170,34,100,30,"供应商");
                                LODOP.ADD_PRINT_TEXT(170,100,307,30,data.rows[i].gys);
                                LODOP.ADD_PRINT_TEXT(200,34,100,30,"生产日期");
                                LODOP.ADD_PRINT_TEXT(200,100,307,30,data.rows[i].scrq);
                                LODOP.ADD_PRINT_BARCODE(210,180,190,40,"EAN128B",data.rows[i].lpn);
                                LODOP.ADD_PRINT_TEXT(255,34,307,30,"货品批号");
                                LODOP.ADD_PRINT_TEXT(255,100,307,30,data.rows[i].hppc);
                                if(i>=0){
                                    LODOP.NewPage();//分页
                                }
                            }
                        }
                        LODOP.PREVIEW();
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;

        };
        var $table = zzpUtils.table({
            elem: '#table1',
            isApi: true,
            pagination: true,
            url: '/wmspalletsorting/baseSelectMx?ssyqdid='+$("#kid").val(),
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'id',
                title: '托盘码'
            }, {
                field: 'goodsBh',
                title: '货品编号'
            }, {
                field: 'goodsMc',
                title: '货品名称'
            },{
                field: 'hppc',
                title: '批次'
            },{
                field: 'scrq',
                title: '生产日期'
            },{
                field: 'gysmc',
                title: '供应商'
            },{
                field: 'yqmpsl',
                title: '预期码盘数量'
            },{
                field: 'sssl',
                title: '实际收货数量'
            },{
                field: 'kwid',
                title: '库位'
            },{
                field: 'th',
                title: 'TI*HI'
            },{
                field: 'caozuo',
                title: '操作',
                events: operateEvent,
                formatter: operateFormatter
            }]
        });
        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {

            return [
                '<a class="layui-btn layui-btn-xs" id="btn_tz">打印</a>'
            ].join('')
        }

        /*顶部按钮多选打印*/
        $(".add-btn").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length > 0) {
                var ids = $.map($rows, function (row) {
                    return row.id;
                    ids.push(row.id);
                })
                zzpUtils.confirm("您将打印选择的订单", function (index) {
                    zzpUtils.action({
                        url: "/wmspalletsorting/baseDyid" ,
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {

                            if(data.title=='码盘明细打印失败'){
                                setTimeout(function () {
                                    layer.msg(data.message);
                                }, 500);
                            }else {

                                var LODOP=getLodop();
                                LODOP.PRINT_INIT('打印码盘信息');
                                for(var i=0;i<data.rows.length;i++){
                                    var oDate = new Date(); //实例一个时间对象；
                                    var time=oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate()+' '+oDate.getHours()+':'+oDate.getMinutes()+':'+oDate.getSeconds();
                                    LODOP.ADD_PRINT_TEXT(28,34,270,30,time);
                                    LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                                    LODOP.ADD_PRINT_BARCODE(48,34,270,47,"EAN128B",data.rows[i].asnbh);
                                    LODOP.ADD_PRINT_TEXT(110,34,100,30,"货品编号");
                                    LODOP.ADD_PRINT_TEXT(110,100,307,30,data.rows[i].bh);
                                    LODOP.ADD_PRINT_TEXT(140,34,100,30,"货品名称");
                                    LODOP.ADD_PRINT_TEXT(140,100,307,30,data.rows[i].mc);
                                    LODOP.ADD_PRINT_TEXT(170,34,100,30,"供应商");
                                    LODOP.ADD_PRINT_TEXT(170,100,307,30,data.rows[i].gys);
                                    LODOP.ADD_PRINT_TEXT(200,34,100,30,"生产日期");
                                    LODOP.ADD_PRINT_TEXT(200,100,307,30,data.rows[i].scrq);
                                    LODOP.ADD_PRINT_BARCODE(210,180,190,40,"EAN128B",data.rows[i].lpn);
                                    LODOP.ADD_PRINT_TEXT(255,34,307,30,"货品批号");
                                    LODOP.ADD_PRINT_TEXT(255,100,307,30,data.rows[i].hppc);
                                    if(i>=0){
                                        LODOP.NewPage();//分页
                                    }
                                }
                            }
                            LODOP.PREVIEW();
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                });
            } else {
                layer.msg("您还未选择，请您至少选择一个!");
            }
        })

    });

</script>
</html>